﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PSDLib.Models
{
    public class BurnRuntime
    {
        public List<RecorderStatus> RecorderStatus { get; set; }
        public List<BurnJob> BurnJobs { get; set; }

        public BurnRuntime()
        {
            RecorderStatus = new List<RecorderStatus>();
            BurnJobs = new List<BurnJob>();
        }

        public RecorderStatus GetRecorderStatus(string recorderId)
        {
            return RecorderStatus.Where(t => t.RecorderId == recorderId).FirstOrDefault();
        }
    }

    public class RecorderStatus
    {
        public string RecorderId { get; set; }
        public string RecorderName { get; set; }
        public int State { get; set; }
        public string Info { get; set; }

        public RecorderStatus()
        {
            RecorderName = "";
            Info = "";
            State = (int)BurnDVDState.等待刻录;
        }
    }

    public class BurnJob
    {
        public string Id { get; set; }
        public dl_burn BurnInfo { get; set; }
        public dl_burn_dvd DVD { get; set; }
        public List<dl_burn_files> Files { get; set; }

        public string RecorderId { get; set; }
        public string RecorderName { get; set; }

        public int State { get; set; }

        public BurnJob()
        {
            Files = new List<dl_burn_files>();
            State = (int)ResultCode.BurnJobWaiting;
        }

        public BurnJob Clone()
        {
            BurnJob newDVD = new BurnJob();

            newDVD.Id = Guid.NewGuid().ToString();
            newDVD.BurnInfo = new dl_burn();
            foreach (var p in typeof(dl_burn).GetProperties())
            {
                p.SetValue(newDVD.BurnInfo, p.GetValue(this.BurnInfo, null), null);
            }
            newDVD.DVD = new dl_burn_dvd();
            foreach (var p in typeof(dl_burn_dvd).GetProperties())
            {
                p.SetValue(newDVD.DVD, p.GetValue(this.DVD, null), null);
            }
            newDVD.Files.AddRange(this.Files);
            newDVD.RecorderId = this.RecorderId;
            newDVD.RecorderName = this.RecorderName;

            return newDVD;
        }
    }
}
